using System;

namespace IOPvsOOP.Chain.NOIF
{
    public class FooPoolChain
    {
        private Func<Foo> foo;

        public FooPoolChain(Foo[] foos)
        {
            Func<Foo> fooRoot = null;

            foo = () =>
            {
                foo = () =>
                {
                    foo = () =>
                    {
                        foo = fooRoot;
                        return foos[2];
                    };
                    return foos[1];
                };
                return foos[0];
            };
            fooRoot = foo;
        }

        public Foo Get()
        {
            return foo();
        }
    }
}